package sk.hackcraft.multibox.android.net;

import java.io.IOException;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.json.JSONException;
import org.json.JSONObject;

abstract public class Request
{
	private RequestCallback callback;
	
	protected HttpClient httpClient;
	protected HttpPost httpPost;
	protected long token;
	
	protected List<NameValuePair> data;
	
	public Request(List<NameValuePair> data)
	{
		this.data = data;
	}
	
	public void prepare(HttpClient httpClient, HttpPost httpPost, long token)
	{
		this.httpClient = httpClient;
		this.httpPost = httpPost;
		this.token = token;
	}
	
	public void setCallback(RequestCallback callback)
	{
		this.callback = callback;
	}
	
	abstract public void run() throws IOException, JSONException;
	
	public RequestCallback getCallback()
	{
		return callback;
	}
	
	abstract public static class RequestCallback
	{
		protected JSONObject data;
		
		public void sendData(String data) throws JSONException
		{
			this.data = new JSONObject(data);
		}
		
		abstract public void run();
	}
}
